package me.jiatao.hilt

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import me.jiatao.hilt.di.AppDataBase
import me.jiatao.hilt.di.Repository
import me.jiatao.hilt.di.RoomModule
import me.jiatao.hilt.di.WorkService
import me.jiatao.hilt.entrypoint.WorkServiceProvider
import me.jiatao.hilt.scopes.ActivityClassB
import me.jiatao.hilt.scopes.FragmentClassC
import javax.inject.Inject

@AndroidEntryPoint
class MainActivity : AppCompatActivity() {

    @Inject
    lateinit var okHttpClient: OkHttpClient
//    @Inject
//    lateinit var repository: Repository
//    @Inject
//    lateinit var appDataBase: AppDataBase


    @Inject
    lateinit var activityClassB: ActivityClassB

    @Inject
    lateinit var activityClassB2: ActivityClassB


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        // 用到了 Fragment 1.2.0 中重要的更新
        // 可以查看之前写的这篇文章 @see https://juejin.im/post/6844904167685750798
        supportFragmentManager.beginTransaction()
            .add(R.id.container, HiltFragment::class.java, null)
            .commit()

//        okHttpClient.post()
//        repository.getData()
//        appDataBase.showInfo()
//        workService.init()

        activityClassB.hello()


        WorkServiceProvider(application).doWork()

        println("MainActivity okHttpClient--->$okHttpClient")


        GlobalScope.launch {
            delay(3000)
            startActivity(Intent(this@MainActivity,MainActivity2::class.java))
        }
    }
}
